package com.dragon.pear.modules.trade.service.assistants.converters;

import java.sql.Timestamp;
import com.dragon.common.base.utils.ConvertUtil;
import com.dragon.common.base.utils.DbUtil;
import com.dragon.common.spring.annotations.DataConverter;
import com.dragon.common.spring.business.base.BaseConverter;
import com.dragon.utils.TimeUtil;
import com.dragon.pear.modules.trade.domain.entity.TradeGoodsOrderEntity;
import com.dragon.pear.modules.trade.web.model.params.create.TradeGoodsOrderCreateParam;
import com.dragon.pear.modules.trade.web.model.params.update.TradeGoodsOrderUpdateParam;
import com.dragon.pear.modules.trade.web.model.results.TradeGoodsOrderResult;

/**
 * @author Chris Chan
 * Create on 2025-09-30 22:06
 * Use for: 订单 业务数据转换助手
 * Explain:
 * 
 */
@DataConverter
public class TradeGoodsOrderConverter implements BaseConverter<
        TradeGoodsOrderEntity,
        TradeGoodsOrderCreateParam,
        TradeGoodsOrderUpdateParam,
        TradeGoodsOrderResult> {
    @Override
    public TradeGoodsOrderEntity fromParam(TradeGoodsOrderCreateParam param) {
        TradeGoodsOrderEntity entity = new TradeGoodsOrderEntity();
        ConvertUtil.copyProperties(param, entity, "id");
        // 生成编码
        entity.setCode(DbUtil.buildCode());
        // 转换时间
        entity.setTime(TimeUtil.now());
        return entity;
    }

    @Override
    public TradeGoodsOrderEntity fromUpdateParam(TradeGoodsOrderUpdateParam param) {
        TradeGoodsOrderEntity entity = ConvertUtil.convert(param, TradeGoodsOrderEntity.class);
        // 转换时间
        entity.setTime(TimeUtil.now());
        return entity;
    }

    @Override
    public TradeGoodsOrderResult toResult(TradeGoodsOrderEntity entity) {
        TradeGoodsOrderResult result = ConvertUtil.convert(entity,TradeGoodsOrderResult.class);
        // 转换时间
        result.setTime(entity.getTime().getTime());
        return result;
    }
}